/*
delete_object.sqf
*/
#include "ACV_Constantes.h"
#include "ACV_ID_main_dlg.h"

private [
	"_display", "_list", "_btn_delete", "_index", "_varname", "_obj",
	"_arr", "_txt_sys", "_i", "_lb", "_msg", "_nb"
];

disableSerialization;

_display = findDisplay ACV_DLG_ID_Main_Dlg;

_list = _display displayCtrl ACV_DLG_ID_Main_ListObjects;
_btn_delete = _display displayCtrl ACV_DLG_ID_Main_DeleteObjects;

_index = lbCurSel ACV_DLG_ID_Main_ListObjects;
_lb = lbSelection _list;
_nb = count _lb;

call ACV_FNCT_ClearAll_WpMarkers;

if( _nb > 0 ) then {
	
	for [{ _i = _nb - 1}, { _i >= 0}, { _i = _i - 1}] do {
		_varname = lbData [ACV_DLG_ID_Main_ListObjects, (_lb select _i)];

		call compile format ["_obj = %1;", _varname];
		
		_arr = [];
		_arr set [ACV_NET_PARAM_OWNER, (name player)];
		_arr set [ACV_NET_PARAM_CLASS, _obj];
		_arr set [ACV_NET_PARAM_DISPLAYNAME, (_list lbText (_lb select _i))];
		
		ACV_NET_DeleteObject = _arr;
		
		if (!IS_Server) then {
			publicVariable "ACV_NET_DeleteObject";
		}else{
			[ACV_NET_DeleteObject] call ACV_FNCT_DeleteObject;
		};
		sleep 0.03; // Laissez Ca OBLIGATOIRE
	};
	
	ACV_MARKER_LOC_Unit setMarkerPosLocal [0,0,0];
	call ACV_FNCT_ClearAll_WpMarkers;
	
	if(_nb == 1) then {
		_msg = format[ localize "STR_MSG_DELETEGROUP", _arr select ACV_NET_PARAM_DISPLAYNAME, (name player)];
		
	}else{
		_msg = format[ localize "STR_MSG_DELETEOBJS", _nb, (name player)];
	};
	[_msg] call ACV_FNCT_BroadcastMessage;
};
	
_btn_delete ctrlEnable false;
